package com.wlb365.financing.modules.schedule.job;

import com.wlb365.financing.common.constants.ApiConstants;
import com.wlb365.financing.common.utils.SdkHelper;
import com.wlb365.financing.modules.constant.JobConstant;
import com.wlb365.sdk.model.CommonRequest;
import com.wlb365.sdk.model.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 同步微利宝交易数据.
 *
 * @author zwh
 * @version 1.0
 */
@Slf4j
@Component
public class TradeDataSyncByWlbJob extends QuartzJobBean {
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("同步微利宝交易数据开始");
        // 获得传入的参数
        Object params = jobExecutionContext.getMergedJobDataMap().get(JobConstant.JOB_MAP_KEY);
        log.info("helloJob is running params={}, time:{}", params, new Date());
        CommonRequest request = new CommonRequest("fs.data-collect.push");
        Map<String, Object> bizParams = new HashMap<>();
        bizParams.put("type", "weilibao");
        request.setBizModel(bizParams);
        CommonResponse response = SdkHelper.execute(request);
        log.info("同步微利宝交易数据完成，结果：" + ApiConstants.SUCCESS_CODE.equals(response.getCode()));
    }

}
